package com.example.yupao.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
//import springfox.documentation.swagger2.annotations.EnableSwagger2;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
//import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @author LittleNight
 * @date 2024/06/16
 *
 * 自定义 Swagger 接口文档的配置
 */

@Configuration
//@EnableSwagger2
@EnableSwagger2WebMvc   // 用这个注解需要把 swagger 的依赖给删除掉,只能有 knife4j的注解
// 用来指定在哪个环境下加载这个bean
@Profile({"dev", "test"})   //版本控制访问, 表示只是在dev 和 test 环境下开启, 线上环境prod访问不了,不能把我们的接口给暴露出去
public class Knife4jConfig {

    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                // 这里一定要标注你控制器的位置
                .apis(RequestHandlerSelectors.basePackage("com.example.yupao.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * api 信息
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("鱼皮用户中心")
                .description("鱼皮用户中心接口文档")
                .termsOfServiceUrl("https://gitee.com/sister-baoers-bodyguard/")
                .contact(new Contact("shier", "https://blog.csdn.net/Jin__Wang?spm=1000.2115.3001.5343","125xxxx@qq.com"))
                .version("1.0")
                .build();
    }
}